package com.mvc.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo.entity.Comment;
import com.mvc.annotation.Controller;
import com.mvc.annotation.RequestMapping;
import com.mvc.core.ModelAndView;


@Controller
@RequestMapping("/comment")
public class CommentController {

	@RequestMapping("/a.do")
	public ModelAndView a(String[] arr, Comment comment) {
		if(arr!=null) {
			System.out.println(arr.length);
		}
		if(comment!=null)
			System.out.println( comment.toString());
		
		
		List<String> list = new ArrayList<String>();
		list.add("汤姆");list.add("杰瑞");
		
		//请求转发和重定向区别：请求转发可以带请求属性给页面，地址栏不变；重定向不行，地址栏会改变；
		ModelAndView model = new ModelAndView("/index.jsp");
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("key", "tom");
		data.put("list", list);
		model.setMap(data);
		//控制层组件每个方法的返回值：要携带返回的视图文件名，返回到视图是请求转发还是重定向，往页面回传一些数据
		return model;
	}
	
	@RequestMapping("/b.do")
	public String b() {
		return "redirect:/1.jsp";
	}
	
	@RequestMapping("/c.do")
	public List<Comment> c() {
		List<Comment> list = new ArrayList<Comment>();
		for (int i = 0; i < 5; i++) {
			Comment comment = new Comment();
			comment.setTitle("评论的标题"+i);
			comment.setContent("评论的内容"+i);
			list.add(comment);
		}
		return list;
	}
	
	@RequestMapping("/d.do")
	public Map<String, Object> d() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Comment> list = new ArrayList<Comment>();
		for (int i = 0; i < 5; i++) {
			Comment comment = new Comment();
			comment.setTitle("评论的标题"+i);
			comment.setContent("评论的内容"+i);
			list.add(comment);
		}
		map.put("data", list);
		map.put("count", 106);
		return map;
	}
	
	@RequestMapping("/save.do")
	public void save() {}
	
	@RequestMapping("/list.do")
	public void list() {
		System.out.println("enter CommentController->list()");
	}
}